//
//  ShopGuideViewController.m
//  ShoppingExperience
//
//  Created by LiYinDi on 15-1-8.
//  Copyright (c) 2015年 RuiBen. All rights reserved.
//

#import "ShopGuideViewController.h"

@interface ShopGuideViewController ()
{
   // NSArray* viewControllers;
    
    NSUInteger previousSelectedIndex;

}
@end

@implementation ShopGuideViewController
@synthesize cellSelectedIndex=_cellSelectedIndex;
@synthesize shopGuideViewControllers = _shopGuideViewControllers;
-(void)viewWillAppear:(BOOL)animated
{
     _cellSelectedIndex=[Global getShopGuideID];
    [self setSelectedIndex:_cellSelectedIndex];
   // [Global setShopCartID:1];
     [Global setOrderID:1];
    [Global setMemberRegisterID:0];
    
    [Global setStyleDetailID:10];
    [Global setHomeCustomID:1];
    
}
- (void)setSelectedIndex:(NSUInteger)selectedIndex
{
    if (selectedIndex<[self.shopGuideViewControllers count]) {
        if (previousSelectedIndex != NSNotFound)
        {
            UIViewController *previousViewController = [self.shopGuideViewControllers objectAtIndex:previousSelectedIndex];
            [previousViewController.view removeFromSuperview];
            [previousViewController removeFromParentViewController];
        }
        
        UIViewController *selectedViewController = [self.shopGuideViewControllers objectAtIndex:selectedIndex];
        [self addChildViewController:selectedViewController];
        selectedViewController.view.frame = CGRectMake(0, 0,948,768);
        selectedViewController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
        [self.view addSubview:selectedViewController.view];
        // remove previously selected view controller (if any)
        previousSelectedIndex=selectedIndex;
    }

}
- (void)setShopGuideViewControllers:(NSArray *)viewControllers
{
    _shopGuideViewControllers = [viewControllers copy];
     previousSelectedIndex=NSNotFound;
    // create tab bar items
}
-(void)shopcartCashierFinish
{
  //  NSLog(@"2222222223");
    [self setSelectedIndex:2];
}
-(void)productItemDetailBackBtnClick;
{
    UIViewController *selectedViewController=[self.shopGuideViewControllers objectAtIndex:1];
    [self addChildViewController:selectedViewController];
    selectedViewController.view.frame= CGRectMake(0, 0, DEFAULT_FirstLevelView_WIDTH, DEFAULT_FirstLevelView_HEIGHT);
    [self.view addSubview:selectedViewController.view];
    
    UIViewController *previousViewController = [self.shopGuideViewControllers objectAtIndex:previousSelectedIndex];
    [previousViewController.view removeFromSuperview];
    [previousViewController removeFromParentViewController];
    previousSelectedIndex=1;

}
-(void)scanResult
{
    UIViewController *selectedViewController=[self.shopGuideViewControllers objectAtIndex:7];
    [self addChildViewController:selectedViewController];
    selectedViewController.view.frame= CGRectMake(0, 0, DEFAULT_FirstLevelView_WIDTH, DEFAULT_FirstLevelView_HEIGHT);
    [self.view addSubview:selectedViewController.view];
    
    UIViewController *previousViewController = [self.shopGuideViewControllers objectAtIndex:previousSelectedIndex];
    [previousViewController.view removeFromSuperview];
    [previousViewController removeFromParentViewController];
    previousSelectedIndex=7;
}
-(void)addToShopCartClick
{
    UIViewController *selectedViewController=[self.shopGuideViewControllers objectAtIndex:2];
    [self addChildViewController:selectedViewController];
    selectedViewController.view.frame= CGRectMake(0, 0, DEFAULT_FirstLevelView_WIDTH, DEFAULT_FirstLevelView_HEIGHT);
    [self.view addSubview:selectedViewController.view];
    
    UIViewController *previousViewController = [self.shopGuideViewControllers objectAtIndex:previousSelectedIndex];
    [previousViewController.view removeFromSuperview];
    [previousViewController removeFromParentViewController];
    previousSelectedIndex=2;
}
-(void)shopCartBackClick
{
  //  NSLog(@"wwwwwww");
    UIViewController *selectedViewController=[self.shopGuideViewControllers objectAtIndex:7];
    [self addChildViewController:selectedViewController];
    selectedViewController.view.frame= CGRectMake(0, 0, DEFAULT_FirstLevelView_WIDTH, DEFAULT_FirstLevelView_HEIGHT);
    [self.view addSubview:selectedViewController.view];
    
    UIViewController *previousViewController = [self.shopGuideViewControllers objectAtIndex:previousSelectedIndex];
    [previousViewController.view removeFromSuperview];
    [previousViewController removeFromParentViewController];
    previousSelectedIndex=7;

}
-(void)addNewMemberBtnClick
{
    UIViewController *selectedViewController=[self.shopGuideViewControllers objectAtIndex:1];
    [self addChildViewController:selectedViewController];
    selectedViewController.view.frame= CGRectMake(0, 0, DEFAULT_FirstLevelView_WIDTH, DEFAULT_FirstLevelView_HEIGHT);
    [self.view addSubview:selectedViewController.view];
    
    UIViewController *previousViewController = [self.shopGuideViewControllers objectAtIndex:previousSelectedIndex];
    [previousViewController.view removeFromSuperview];
    [previousViewController removeFromParentViewController];
    previousSelectedIndex=1;
}
-(void)styleDetailBackClick
{
    UIViewController *selectedViewController=[self.shopGuideViewControllers objectAtIndex:2];
    [self addChildViewController:selectedViewController];
    selectedViewController.view.frame= CGRectMake(0, 0, DEFAULT_FirstLevelView_WIDTH, DEFAULT_FirstLevelView_HEIGHT);
    [self.view addSubview:selectedViewController.view];
    
    UIViewController *previousViewController = [self.shopGuideViewControllers objectAtIndex:previousSelectedIndex];
    [previousViewController.view removeFromSuperview];
    [previousViewController removeFromParentViewController];
    previousSelectedIndex=2;
}
-(void)memberRegisterBackBtnClick
{
    if ([ Global getMemberRegisterID]==4||[Global getMemberRegisterID]==5) {
        
   
    UIViewController *selectedViewController=[self.shopGuideViewControllers objectAtIndex:[ Global getMemberRegisterID]];
    [self addChildViewController:selectedViewController];
    selectedViewController.view.frame= CGRectMake(0, 0, DEFAULT_FirstLevelView_WIDTH, DEFAULT_FirstLevelView_HEIGHT);
    [self.view addSubview:selectedViewController.view];
    
    UIViewController *previousViewController = [self.shopGuideViewControllers objectAtIndex:previousSelectedIndex];
    [previousViewController.view removeFromSuperview];
    [previousViewController removeFromParentViewController];
    previousSelectedIndex=[ Global getMemberRegisterID];
    }

}
- (void)viewDidLoad {
    [super viewDidLoad];
    
        // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
